package net.zoneland.geological.station.service;


import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.UUID;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import net.zoneland.geological.station.dao.Tbl_station_warnoptionDao;
import net.zoneland.geological.station.entity.Tbl_station_warnoption;

/**
 * tbl_station_warnoption[设备预警项配置表]表操作Serfice实现类

 * 表   名：TBL_STATION_WARNOPTIONSERVICEIMPL<br/>
 * 注   释：设备预警项配置表<br/>
 * 作   者：李义<br/>
 * 日   期：2017-06-19 19:52:20
**/
@Service("tbl_station_warnoptionService")
public class Tbl_station_warnoptionServiceImpl implements Tbl_station_warnoptionServiceI { 

	public static Logger logger = Logger.getLogger(Tbl_station_warnoptionServiceImpl.class);

	/**
	 * 自动注入DAO对象
	**/
	@Autowired
	private Tbl_station_warnoptionDao tbl_station_warnoptionDao;

	/**
	 * 新增或者更新数据方法接口
	**/
	@Override
	public Tbl_station_warnoption addOrUpdate( Tbl_station_warnoption tbl_station_warnoption )  throws Exception{
		if ( tbl_station_warnoption == null ) {
			logger.error(Tbl_station_warnoption.class.getName() + "对象参数信息为NULL，addOrUpdate方法无法继续！");
			return tbl_station_warnoption;
		}
		Map<String, Object> map = new HashMap<String, Object>();
		if( tbl_station_warnoption.getId() ==null || "".equals( tbl_station_warnoption.getId().trim() ) ){
			map.put( "id", "0000-0000-0000-0000" );
		}else{
			map.put( "id", tbl_station_warnoption.getId() );
		}
		List<Tbl_station_warnoption> list  = tbl_station_warnoptionDao.getList(map);
		if( list != null && !list.isEmpty() ){
			if( tbl_station_warnoption.getCreate_time() == null ){
				tbl_station_warnoption.setCreate_time( new Date() );
			}
			if( tbl_station_warnoption.getUpdate_time() == null ){
				tbl_station_warnoption.setUpdate_time( new Date() );
			}
			tbl_station_warnoptionDao.edit( tbl_station_warnoption );
			return tbl_station_warnoption;
		}else{
			if( tbl_station_warnoption.getId() ==null || tbl_station_warnoption.getId().trim().isEmpty() ){
				tbl_station_warnoption.setId( UUID.randomUUID() + "" );
		    }
			if( tbl_station_warnoption.getCreate_time() == null ){
				tbl_station_warnoption.setCreate_time( new Date() );
			}
			if( tbl_station_warnoption.getUpdate_time() == null ){
				tbl_station_warnoption.setUpdate_time( new Date() );
			}
			tbl_station_warnoptionDao.add( tbl_station_warnoption );
			return tbl_station_warnoption;
		}
	}
	/**
	 * 新增数据方法实现
	**/
	@Override
	public boolean add(Tbl_station_warnoption tbl_station_warnoption) throws Exception{
		tbl_station_warnoptionDao.add( tbl_station_warnoption );
		return true;
	}
	/**
	 * 更新数据方法实现
	**/
	@Override
	public boolean update(Tbl_station_warnoption tbl_station_warnoption) throws Exception{
		tbl_station_warnoptionDao.edit( tbl_station_warnoption );
		return true;
	}
	/**
	 * 查询数据方法实现
	**/
	@Override
	public Tbl_station_warnoption get( Map<String, Object> map ) throws Exception{
		return tbl_station_warnoptionDao.get( map );
	}
	/**
	 * 查询数据方法实现（列表）
	**/
	@Override
	public List<Tbl_station_warnoption> getList(Map<String, Object> map) throws Exception{ 
		return tbl_station_warnoptionDao.getList( map );
	}
	
	/**
	 * 查询数据总数方法实现
	**/
	@Override
	public int getListCount(Map<String, Object> map) throws Exception{ 
		return tbl_station_warnoptionDao.getListCount( map );
	}
	
	/**
	 * 数据删除方法实现
	**/
	@Override
	public boolean delete(Map<String, Object> map) throws Exception{ 
		tbl_station_warnoptionDao.delete( map );
		return true;
	}
	@Override
	public List<String> getListDistinctNames(Map<String, Object> paramMap) throws Exception {
		return tbl_station_warnoptionDao.getListDistinctNames( paramMap );
	}
	
}
